Data Adaptor - Sample Code (Autosave with Derby)

Data Adaptor - Sample Code (Autosave with Derby)

The sample Autosave scenario in this example does the following:

 

The sample code demonstrates

 

The sample code provides functionality for requirements such as the need to be able to autosave based on triggers.

Setup

This sample code needs the following to run:

About the DERBY SQL database schema

The DERBY SQL database is created by using create_db.sql which is located in examples\web-determinations\auto-save\src.

AUTOSAVE
ID
age
income
old
low_income
old_low_income
eligible

About the Plugins:

To setup this scenario:

  1. Create the SQL Database using create_db.sql which can be found in examples\web-determinations\auto-save\src

  2. Copy the rulebase .zip file (ExtFrameworkAutoSave.zip) from examples\rulebases\compiled to the rulebase folder in Web Determinations (for example, <webroot>\WEB-INF\classes\rulebases)
  3. Copy and install the DerbyAutoSave.jar file (located in examples\web-determinations\auto-save) into Web Determinations; for more information, refer to Create a Plugin
  4. Copy the DERBY libraries to the library folder in Web Determinations (for example, <webroot>\WEB-INF\lib)

  5. Ensure that DERBY is run in network server mode

  6. Run a Web Determinations Interview

 

Note:

If you need to modify the database connection details or you need class files for your specific database implementation, then you will need to edit the source code, recompile and JAR the DerbyAutoSave.

How the Autosave works

The autosave functionality happens:

 

When the above events are met, the AutosaveTrigger Event Handler calls the save() method of the AutosaveSaver Data Adaptor.

The AutosaveSaver simply saves all of the attributes into the Autosave table in the DERBY database.

 

Table AUTOSAVE 

ID age income old low_income old_low_income eligible
VARCHAR(255) DOUBLE DOUBLE INT INT INT INT

 

Table 'Autosave' view - start of investigation, to completing an investigation

While going through the Interview, when the user starts an investigation of a goal and the current Case ID is empty - a new Case ID will be created. You can see this in the database; for example:


ID age income old low_income old_low_income eligible
8821b2f8-76e3-4762-a4a5-af8c10aac521 NULL
NULL NULL NULL NULL NULL

 

After the Case ID is generated, as the user answers the questions in the investigation (for example, age=31 below), answers and inferenced data will be added onto the same row item in the database (for example, old = Yes, eligible = Yes).


ID age income old low_income old_low_income eligible
8821b2f8-76e3-4762-a4a5-af8c10aac521 31
NULL Yes NULL NULL Yes

Source Code

To view the source code for the DerbyAutoSave sample, refer to examples\web-determinations\auto-save in the Java runtime zip file.